/*
 * @Copyright: (C) 2019 Zhang Rida. All rights reserved.
 *
 * @Author: Zhang Rida
 * @Email: 215154317@qq.com
 * @FilePath: /WEILA_SDK_MODULE/src/wlsdk/src/protocol_client.h
 * @Date: 2021-02-27 17:08:35
 * @Description:
 *
 * @LastEditors: Zhang Rida
 * @LastEditTime: 2023-08-24 16:31:30
 */
#ifndef _PROTOCOL_CLIENT_H
#define _PROTOCOL_CLIENT_H

#include "weilapb_defines.h"
#include "wl_osal.h"

#ifdef __cplusplus
extern "C" {
#endif

#define PROTOCOL_CLIENT_REQUEST_TIMEOUT_5 5000
#define PROTOCOL_CLIENT_REQUEST_TIMEOUT_10 10000
#define PROTOCOL_CLIENT_REQUEST_TIMEOUT_15 15000
#define PROTOCOL_CLIENT_REQUEST_TIMEOUT_30 30000
#define PROTOCOL_CLIENT_REQUEST_TIMEOUT_60 60000
#define PROTOCOL_CLIENT_REQUEST_TIMEOUT_120 120000

typedef enum {
    PROTOCOL_CLIENT_STATE_DISCONNECTED = 0,
    PROTOCOL_CLIENT_STATE_CONNECTING   = 1,
    PROTOCOL_CLIENT_STATE_CONNECTED    = 2
} protocol_client_state;

// 会话依赖
typedef enum {
    PROTOCOL_CLIENT_SESSION_DEPEND_NONE    = 0x00,
    PROTOCOL_CLIENT_SESSION_DEPEND_FRIEND  = 0x01,
    PROTOCOL_CLIENT_SESSION_DEPEND_GROUP   = 0x02,
    PROTOCOL_CLIENT_SESSION_DEPEND_CONFIRM = 0x03
} protocol_client_session_depend;

typedef wl_int32 (*protocol_client_state_callback)(wl_uint32 state);
typedef wl_int32 (*protocol_client_request_callback)(PBWeilaMsg* message,
                                                     void*       content,
                                                     wl_uint32   contentlen,
                                                     void*       context);
typedef wl_int32 (*protocol_client_listen_callback)(PBWeilaMsg* message, void* context);

wl_int32 protocol_client_init(protocol_client_state_callback callback);

wl_int32 protocol_client_end(void);

wl_int32 protocol_client_get_state(void);

void protocol_client_set_session_depend(protocol_client_session_depend depend);

protocol_client_session_depend protocol_client_get_session_depend(void);

wl_int32 protocol_client_connect_server(wl_char* server_addr, wl_uint16 server_port, wl_uint32 timeout);

wl_int32 protocol_client_disconnect(void);

wl_time protocol_client_get_latest_recv_timestamp(void);

wl_uint32 protocol_client_get_recv_bytes(void);

wl_int32 protocol_client_send_response(PBEncResult* encResult);

wl_int32 protocol_client_clear_request(wl_uint32 msgid);

wl_int32 protocol_client_send_request(PBEncResult*                     encResult,
                                      void*                            content,
                                      wl_uint32                        contentlen,
                                      wl_uint32                        timeout,
                                      protocol_client_request_callback callback,
                                      void*                            context);

wl_int32 protocol_client_add_listen(wl_uint32                       msgid,
                                    wl_uint16                       commandtype,  // 参考COMMAND_TYPE
                                    protocol_client_listen_callback callback,
                                    void*                           context);

#ifdef __cplusplus
}
#endif
#endif
